package com.xiaoye.digitaltwin.service.impl;

import com.xiaoye.digitaltwin.common.NullParameterException;
import com.xiaoye.digitaltwin.entity.Waiyacontrol;
import com.xiaoye.digitaltwin.entity.dao.WaiyaConfirm;
import com.xiaoye.digitaltwin.mapper.WaiyacontrolMapper;
import com.xiaoye.digitaltwin.service.IWaiyacontrolService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 外压控制表 服务实现类
 * </p>
 *
 * @author xiaoye
 * @since 2023-08-19
 */
@Service
public class WaiyacontrolServiceImpl extends ServiceImpl<WaiyacontrolMapper, Waiyacontrol> implements IWaiyacontrolService {

    @Override
    public Waiyacontrol check(WaiyaConfirm waiyaConfirm) {
        Double length1 = waiyaConfirm.getLength1();
        Double length2 = waiyaConfirm.getLength2();
        Double length3 = waiyaConfirm.getLength3();
        Double avelength = waiyaConfirm.getAvelength();

        Double outerMax1 = waiyaConfirm.getOuterMax1();
        Double outerMax2 = waiyaConfirm.getOuterMax2();
        Double outerMax3 = waiyaConfirm.getOuterMax3();
        Double aveoutermax = waiyaConfirm.getAveoutermax();

        Double outerMin1 = waiyaConfirm.getOuterMin1();
        Double outerMin2 = waiyaConfirm.getOuterMin2();
        Double outerMin3 = waiyaConfirm.getOuterMin3();
        Double aveoutermin = waiyaConfirm.getAveoutermin();

        Double wallThick1 = waiyaConfirm.getWallThick1();
        Double wallThick2 = waiyaConfirm.getWallThick2();
        Double wallThick3 = waiyaConfirm.getWallThick3();
        Double avewallthick = waiyaConfirm.getAvewallthick();

        Double initDefect1 = waiyaConfirm.getInitDefect1();
        Double initDefect2 = waiyaConfirm.getInitDefect2();
        Double initDefect3 = waiyaConfirm.getInitDefect3();
        Double aveinitdefect = waiyaConfirm.getAveinitdefect();

        if (length1 == null || length2 == null || length3 == null || avelength == null){
            throw new NullParameterException("长度为空");
        }

        if (outerMax1 == null || outerMax2 == null || outerMax3 == null){
            throw new NullParameterException("外径最大值为空");
        }

        if(outerMin1 == null || outerMin2 == null || outerMin3 ==null || aveoutermin == null){
            throw new NullParameterException("外径最小值为空");
        }

        if (wallThick1 == null || wallThick2 == null || wallThick3 == null || avewallthick == null){
            throw new NullParameterException("壁厚为空");
        }

        if (initDefect1 == null || initDefect2 == null || initDefect3 == null || aveinitdefect == null){
            throw new NullParameterException("初始缺陷为空");
        }

        //这里未校验数据是否在正常范围内   你们可以后续补充


        Waiyacontrol waiyacontrol = new Waiyacontrol();
        waiyacontrol.setLength1(length1);
        waiyacontrol.setLength2(length2);
        waiyacontrol.setLength3(length3);
        waiyacontrol.setAvelength(avelength);

        waiyacontrol.setOuterMax1(outerMax1);
        waiyacontrol.setOuterMax2(outerMax2);
        waiyacontrol.setOuterMax3(outerMax3);
        waiyacontrol.setAveoutermax(aveoutermax);

        waiyacontrol.setOuterMin1(outerMin1);
        waiyacontrol.setOuterMin2(outerMin2);
        waiyacontrol.setOuterMin3(outerMin3);
        waiyacontrol.setAveoutermin(aveoutermin);

        waiyacontrol.setWallThick1(wallThick1);
        waiyacontrol.setWallThick2(wallThick2);
        waiyacontrol.setWallThick3(wallThick3);
        waiyacontrol.setAvewallthick(avewallthick);

        waiyacontrol.setInitDefect1(initDefect1);
        waiyacontrol.setInitDefect2(initDefect2);
        waiyacontrol.setInitDefect3(initDefect3);
        waiyacontrol.setAveinitdefect(aveinitdefect);
        return waiyacontrol;
    }
}
